package GUI;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import javax.swing.AbstractListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.JScrollBar;
import javax.swing.JLabel;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

import java.awt.Font;
import java.awt.Color;

import javax.swing.JTextField;
import javax.swing.JButton;



import UserData.User_Info;
import UserData.User_Management;

import com.toedter.calendar.JCalendar;
import com.toedter.calendar.JDateChooser;
import com.toedter.calendar.JDateChooserBeanInfo;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTable;
import javax.swing.JRadioButton;

public class NormalUser extends JFrame {

   /**
    * Main.
    */
/*   public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
         public void run() {
            try {
               NormalUser frame = new NormalUser();
               frame.setVisible(true);
            } catch (Exception e) {
               e.printStackTrace();
            }
         }
      });
   }
*/
   /**
    * Variable.
    */
   private JPanel contentPane;
   private JTabbedPane tabbedPane;
   private JPanel panelMain;
   private JButton btnMain;
   private JLabel lblCurrentTime;
   private JLabel lblNextMeeting;
   private JPanel panelGraph;
   private BarChart bc;
   private DigitalClock digitclock;
   private MyPage mypagetabbedPane;
   private Compare comparetabbledPane;
   private BarChart barcharttabbedPane;
   
   
   private JPanel testPane;
   
   int mainBtnCount;
   int temp;
   
   private void initVar(){

	   
	   
	   Runnable thj= new AlarmRunner();
		
		Thread th = new Thread(thj);
		th.start();

      contentPane = new JPanel(){
         @Override
         public void paintComponent(Graphics g){
            Image image = new ImageIcon("normaluser.png").getImage();
            g.drawImage(image, 0, 0, this);
         }      
      };
      JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
      /*{
         public void paintComponent(Graphics g){
            Image image = new ImageIcon("tabbbbbbbbbb.png").getImage();///////////////////////////
            g.drawImage(image, 0, 0, this);
         }      
      }*/;
      mypagetabbedPane = new MyPage();
      barcharttabbedPane = new BarChart();
      panelMain = new JPanel();
      comparetabbledPane = new Compare();
      btnMain = new JButton("Button"){
         public void paintComponent(Graphics g){
            Image image = new ImageIcon("car.png").getImage();
            
            g.drawImage(image, 0, 0, this);
         }      
      };
      btnMain.setBorder(null);
      btnMain.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            btnMainActionPerformed(e);
         }
      });
      
      
      
      digitclock=new DigitalClock("HHmmss");
      lblCurrentTime = new DigitalClock();
      lblCurrentTime.setForeground(Color.GRAY);
      lblCurrentTime.setFont(new Font("Century Gothic", Font.BOLD, 90));
      lblNextMeeting = new JLabel("Next Meeting");

      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);


      tabbedPane.setBounds(56, 38, 730, 500);
      contentPane.add(tabbedPane);




      Icon tabmain = new ImageIcon("tabmain.png");
      Icon tabmypage = new ImageIcon("tabmypage.png");
      Icon tabgraph = new ImageIcon("tabgraph.png");
      Icon tabcompare = new ImageIcon("tabcompare.png");

      tabbedPane.addTab("", tabmain, panelMain, null);
      panelMain.setLayout(null);



      btnMain.setBounds(247, 327, 97, 23); 

      btnMain.setBounds(250, 320, 250, 100);//if(占쏙옙占썲가占쏙옙占쏙옙擔챨占�-15<占쏙옙占쏙옙챨占�&&占쏙옙튼占쏙옙 占싼뱄옙占쏙옙 占쏙옙占쏙옙占쏙옙 占십억옙占쏙옙占쏙옙){  btnMain enable } 

      panelMain.add(btnMain);



      lblCurrentTime.setBounds(206, 64, 410, 173);
      panelMain.add(lblCurrentTime);

      lblNextMeeting.setBounds(250, 235, 97, 39);
      panelMain.add(lblNextMeeting);

      /**
       * Start My Page.
       */


      tabbedPane.addTab("", tabmypage, mypagetabbedPane, null);


      /**
       * End My Page.
       */
      
        

      tabbedPane.addTab("", tabcompare, comparetabbledPane, null);
      
          panelGraph = new JPanel();
          panelGraph.setLayout(null);
      
      tabbedPane.addTab("", tabgraph, panelGraph, null);
      
            testPane=new BarChart();
            testPane.setBounds(0, 0, 725, 296);
            panelGraph.add(testPane);
      
      
      mainBtnCount=0;
      
      
      
   }

   public NormalUser() {


      initVar();
      setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      setBounds(100, 100, 840, 640);
   }
   
   public void btnMainActionPerformed(ActionEvent e){
       
      
      int compareTime=Integer.parseInt(digitclock.getText());
      int targetTime = 0;//가장가까운시간
      if(timeCompare(targetTime, compareTime)<1500&&mainBtnCount==0){
         
         if(targetTime<compareTime){
        	
        	 temp=+timeCompare(compareTime, targetTime);
            User_Management.Now_User.setLateTime(temp);
         }
         
         
      }
      
   }
   
   public int timeCompare(int big, int sm){
      
      int c =0;
      int temp =((big/10000) - (sm/10000));
      
      big=big-temp*4000;
      c=big-sm;
      
      
      return c;
   }
   
   
}



